package com.jiazhong.basic.pack0718;

import java.lang.reflect.Method;

public class DemoD {
    public static void main(String[] args) throws Exception {
        Class c = Class.forName("com.jiazhong.pack0718.Student");

        // 获取到定义的所有方法
        Method[] declaredMethods = c.getDeclaredMethods();
        // 获取到拥有的所有非私有方法
        Method[] methods = c.getMethods();
        for (Method m : declaredMethods) {
            System.out.println(m);
        }
        System.out.println("---------------------------------");
        for (Method m : methods) {
            System.out.println(m);
        }
        System.out.println("---------------------------------");
        // 获取到具体的某个定义方法
        Method method1 = c.getDeclaredMethod("play", String.class);
        Method method2 = c.getMethod("getBirthday");
        System.out.println(method1);
        System.out.println(method2);
        System.out.println("---------------------------------");
        // 调用方法
        Object obj = c.getDeclaredConstructor().newInstance();
        Object result1 = method1.invoke(obj, "张三");
        Object result2 = method2.invoke(obj);
        System.out.println(result1);
        System.out.println(result2);
    }
}
